
import os
import shutil
import sys
import time
import math
import json
import zipfile

import FileUtils

curPath = os.getcwd()
print(curPath)

# projectPath = os.path.abspath(os.path.join(os.path.dirname(curPath), os.pardir))
# print(projectPath)

import platform
sysstr = platform.system()
print(platform)

pngList = []

size = 0
compressSize = 0

def CompressedPng():

    def callback(filepath,filename):
        # global size
        # global compressSize
        # # print("filepath = " + filepath)
        # size = size + FileUtils.getFileSize(filepath)
        # command = "pngquant --quality=65-80 --force --ext .png " + filepath
        # os.system(command)
        
        # compressSize = compressSize + FileUtils.getFileSize(filepath)
        
        # print("size,compressSize= %d ----> %d"%(size,compressSize))

        pngList.append(filepath)
        pass
    FileUtils.diguiDirWithTail(os.path.join(curPath,"../build/bytedance"),callback,".png")


    fileLen = len(pngList)
    # 一个一个压缩
    # for filepath in pngList:
    for index in range(fileLen):
        filepath = pngList[index]
        global size
        global compressSize
        # print("filepath = " + filepath)
        size = size + FileUtils.getFileSize(filepath)
        if sysstr == "Windows":
            command = "start pngquant --quality=65-80 --force --ext .png " + filepath
            os.system(command)
        else:
            command = "nohup pngquant --quality=65-80 --force --ext .png " + filepath + " >/dev/null 2>&1 &"
            os.system(command)
        compressSize = compressSize + FileUtils.getFileSize(filepath)
        print("size,compressSize = %d ----> %d ##### %d %%"%(size,compressSize,index / fileLen * 100))


    pass




#arg[1]:渠道名:proj.ios_mac_appstore
if __name__ == "__main__":
	

    CompressedPng()


    pass



